package com.feishi.core.util.bitbyte.dbc;

import com.feishi.core.util.common.StringUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class DBCMsg {

    private final int id;
    private String msgName;
    private final int length;
    private final String sender;
    private List<DBCSignal> dbcSignals=new ArrayList<>();

    public DBCMsg(String data) {
        //BO_ 881 BCM_LightDoor_0x371: 8 BCM
        List<String> result = StringUtil.matchAll("^BO_ ([^ ]+) ([^:]+): (\\d+) (.+)$", data);
        this.id= Integer.parseInt(result.get(0));
        this.msgName=result.get(1);
        this.msgName=this.msgName.substring(0,this.msgName.length());
        this.sender=result.get(3);
        this.length=Integer.parseInt(result.get(2));
    }
// SG_ BCM_ReverseLightSts : 0|1@0+ (1,0) [0|1] "" GW
    public boolean readLine(String line) {
        if(!line.startsWith(" "+DBCDefine.SG_))return false;
        dbcSignals.add(new DBCSignal(line));
        return true;
    }
}
